﻿using Iworld.ViewModel;
using System;
using System.Net;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Iworld.Client.Framework
{
    public class ClientViewModelService : ViewModelServiceBase<Page,Pop>
    {
        private static ClientViewModelService current;

        /// <summary>
        /// 当前的客户端视图模型服务
        /// </summary>
        public static ClientViewModelService Current
        {
            get
            {
                if (current == null)
                {
                    throw new Exception("视图模型不存在");
                }
                return current;
            }
        }

        private ClientViewModelService(IMainPage<Page, Pop> root)
            : base(root)
        {}


        protected override void OnJumped(PageCreaterKey key)
        {
            base.OnJumped(key);
            if(key.IsDefault)
            {
                DataManager.RemoveValue(DataKey.Iworld_Token); 
                DataManager.RemoveValue(DataKey.SettingOfGame);
                DataManager.RemoveValue(DataKey.GameInfo);
            }
        }

        public static void Initialize(IMainPage<Page, Pop> root)
        {
            if (current != null)
            {
                throw new Exception("已经初始化");
            }
            current = new ClientViewModelService(root);
            current.JumpToDefaultPage();
        }

        protected override Assembly GetViewModelAssembly()
        {
            return Assembly.GetExecutingAssembly();
        }

        protected override string GetViewModelName(string pageTypeName)
        {
           return string.Format("Iworld.Client.Framework.{0}",new Regex("Page").Replace(pageTypeName,"ViewModel"));
        }
    }

  
}
